package com.puzzlebazar.client.main.model;

import java.util.HashMap;

import com.google.gwt.user.client.ui.Hyperlink;
import com.puzzlebazar.client.main.control.HistoryController;

public class Link {

	private final String name;	
	private final String token;
	private final HashMap<String,String> params;
	
	
	/**
	 * Creates a link that can point to any page
	 * 
	 * @param name The name of this link
	 * @param token The associated token
	 * @param params All the parameters for the link (can be null if no parameters)
	 */
	public Link( String name, String token, HashMap<String,String> params ) {
	
		this.name = new String(name); 
		this.token = new String(token);
		if( params == null )
			this.params = null;
		else
			this.params = new HashMap<String,String>( params );
	}
	
	
	/**
	 * Creates an hyperlink using the content of the link and a specific 
	 * history controller to build the token
	 * 
	 * @param tokenBuilder The controller to use to build the token
	 * @return The resulting hyperlink
	 */
	public Hyperlink buildHyperlink( HistoryController tokenBuilder ) {
		
		return new Hyperlink(name, tokenBuilder.buildToken(token, params));		
	}
}
